package cn.edu.ctbu.datajpt18.controller;

import cn.edu.ctbu.datajpt18.domain.Student;
import cn.edu.ctbu.datajpt18.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class StudentController {
    @Autowired
    private StudentRepository studentRepository;

    @GetMapping("/students")
    public String showStudents(Model model) {
        List<Student> students=studentRepository.findAll();
        model.addAttribute("students",students);
        return "students";
    }
}

